home *** CD-ROM | disk | FTP | other *** search
/ MACD 5 / MACD 5.bin / workbench / libs / maestixlib.lha / Maestix / demos / LevelWindow.s < prev    next >
Text File  |  1995-02-25  |  13KB  |  398 lines

  1. *****************************************************************
  2. *                                *
  3. *    maestix.library-Demo:    LevelWindow            *
  4. *                                *
  5. *****************************************************************
  6. *
  7. *    Programmed by        Richard Körber
  8. *    Date            1995-01-30
  9. *
  10. *****************************************************************
  11. *  This demonstration shows the basic receive functions of the  *
  12. *  maestix library. It allocates the Maestro soundcard, select    *
  13. *  the default  input and  displays the level  of the incoming    *
  14. *  signal using an intuition window.                *
  15. *****************************************************************
  16.  
  17.         INCDIR    "include:"
  18.         INCLUDE    exec.i            ; Library call macros
  19.         INCLUDE    intuition.i
  20.         INCLUDE    graphics.i
  21.         INCLUDE    dos.i
  22.         INCLUDE    maestix.i
  23.         INCLUDE    libraries/maestix.i    ;Reference includes
  24.         INCLUDE    intuition/intuition.i
  25.         INCLUDE    dos/dostags.i
  26.         INCLUDE    exec/ports.i
  27.  
  28. BUFSIZE        EQU    12*1024            ;size of FIFO data block
  29. WINDOW_WIDTH    EQU    50            ;width of output window
  30.  
  31.         SECTION text,CODE
  32.  
  33. *---------------------------------------------------------------*
  34. *    == START OF PROGRAM ==                    *
  35. *                                *
  36. start    ;-- Open all libraries -----------------;
  37.         lea    maestname(PC),a1    ;maestix
  38.         moveq    #35,d0            ; V35+
  39.         exec    OpenLibrary        ; open
  40.         move.l    d0,maestbase        ; store base
  41.         beq    error1            ; not found!
  42.         lea    intuiname(PC),a1    ;intuition
  43.         moveq    #36,d0            ; V36+
  44.         exec    OpenLibrary        ; open
  45.         move.l    d0,intuibase        ; store base
  46.         beq    error2            ; not found!
  47.         lea    gfxname(PC),a1        ;graphics
  48.         moveq    #36,d0            ; V36+
  49.         exec    OpenLibrary        ; open
  50.         move.l    d0,gfxbase        ; store base
  51.         beq    error3            ; not found!
  52.         lea    dosname(PC),a1        ;dos
  53.         moveq    #36,d0            ; V36+
  54.         exec    OpenLibrary        ; open
  55.         move.l    d0,dosbase        ; store base
  56.         beq    error4
  57.     ;-- Create buffer ----------------------;
  58.         move.l    #BUFSIZE*3,d0        ;size of three buffers
  59.         move.l    #$10001,d1        ;PUBLIC|CLEAR
  60.         exec    AllocMem
  61.         move.l    d0,buffer
  62.         beq    error5
  63.     ;-- Alloc signal bits ------------------;
  64.         sub.l    a1,a1            ;get task ptr
  65.         exec    FindTask
  66.         move.l    d0,disptask
  67.         moveq    #-1,d0            ;Allocate a signal bit
  68.         exec    AllocSignal
  69.         move.b    d0,dispsigbit
  70.         cmp.b    #-1,d0            ;no signals free?
  71.         beq.w    error6
  72.         moveq    #-1,d0            ;Allocate a 2nd signal bit
  73.         exec    AllocSignal
  74.         move.b    d0,donesigbit
  75.         cmp.b    #-1,d0            ;no signals free?
  76.         beq.w    error7
  77.     ;-- Open output window -----------------;
  78.         sub.l    a0,a0            ;no newwindow struct
  79.         lea    windowtags(PC),a1    ; but loads of tags
  80.         intui    OpenWindowTagList
  81.         move.l    d0,window
  82.         beq    error8
  83.     ;-- Launch level task ------------------;
  84.         move.l    #tasktags,d1        ;Tags for new task
  85.         dos    CreateNewProc        ;create new process
  86.         tst.l    d0            ;got the task?
  87.         beq    error9
  88.         moveq    #0,d0            ;wait 'till 2nd task setup'd
  89.         move.b    donesigbit(PC),d1    ; signal
  90.         bset    d1,d0
  91.         exec    Wait            ;wait for this event
  92.     ;-- Wait for reply (main loop) ---------;
  93. .mainloop    move.l    window(PC),a0        ;window message?
  94.         move.l    wd_UserPort(a0),a0    ; ^message port
  95.         exec    GetMsg            ; try to get it...
  96.         tst.l    d0            ; got one?
  97.         bne.b    .gotwindow        ; then evaluate it
  98.         moveq    #0,d0            ;create wait mask
  99.         move.b    dispsigbit(PC),d1    ; signal for re-displaying
  100.         bset    d1,d0
  101.         move.l    window(PC),a0        ; second, from window
  102.         move.l    wd_UserPort(a0),a0    ;  message port
  103.         move.b    MP_SIGBIT(a0),d1    ; sig bit
  104.         bset    d1,d0            ; set this bit
  105.         exec    Wait            ;wait for these events
  106.         move.b    dispsigbit(PC),d1    ; re-display wanted?
  107.         btst    d1,d0            ; test this bit
  108.         beq.b    .mainloop        ;not wanted -> main loop
  109.     ;---- got a draw signal ----------------;
  110. .drawsig    moveq    #0,d0            ;D0: x coordinate left
  111.         move    leftlevel,d1        ;D1: left level
  112.         lsr    #8,d1            ; (Range 0..128)
  113.         move    oldleft(PC),d2        ;D2: old left level
  114.         move    d1,oldleft        ; store new "old" level
  115.         bsr    drawlevel        ;draw this level
  116.         moveq    #WINDOW_WIDTH/2,d0    ;D0: x coordinate left
  117.         move    rightlevel,d1        ;D1: right level
  118.         lsr    #8,d1            ; (Range 0..128)
  119.         move    oldright(PC),d2        ;D2: old right level
  120.         move    d1,oldright        ; store new "old" level
  121.         bsr    drawlevel        ;draw this level
  122.         bra.b    .mainloop        ;and do the mainloop
  123.     ;---- got a window event ---------------;
  124. .gotwindow    move.l    d0,a0            ;^IDCMP-message -> a0
  125.         cmp.l    #IDCMP_CLOSEWINDOW,im_Class(a0) ;close window?
  126.         bne.b    .mainloop        ; no -> continue being idle ;)
  127.     ;-- Exit program -----------------------;
  128. exit        move.l    leveltask(PC),a1    ;Shut level task
  129.         moveq    #0,d0
  130.         move.b    levelsigbit(PC),d1
  131.         bset    d1,d0
  132.         exec    Signal            ; signals the exit
  133.         moveq    #0,d0            ;wait 'till 2nd task exited
  134.         move.b    donesigbit(PC),d1    ; signal
  135.         bset    d1,d0
  136.         exec    Wait            ;wait for this event
  137. error9        move.l    window(PC),a0        ;Close output window
  138.         intui    CloseWindow
  139. error8        move.b    donesigbit(PC),d0
  140.         exec    FreeSignal
  141. error7        move.b    dispsigbit(PC),d0    ;Get display task signal bit
  142.         exec    FreeSignal
  143. error6        move.l    buffer(PC),a1        ;^Buffer
  144.         move.l    #BUFSIZE*3,d0
  145.         exec    FreeMem
  146. error5        move.l    dosbase(PC),a1        ;close dos library
  147.         exec    CloseLibrary
  148. error4        move.l    gfxbase(PC),a1        ;close graphics library
  149.         exec    CloseLibrary
  150. error3        move.l    intuibase(PC),a1    ;close intuition library
  151.         exec    CloseLibrary
  152. error2        move.l    maestbase(PC),a1    ;close maestix library
  153.         exec    CloseLibrary
  154. error1        moveq    #0,d0            ;Reply 0
  155.         rts                ;back to CLI
  156.  
  157. *-------------------------------------------------------*
  158. * drawlevel    draws the level to window        *
  159. *    -» D0.w    x-coord                    *
  160. *    -» D1.w    new level                *
  161. *    -» D2.w    old level                *
  162. *                            *
  163. drawlevel    movem.l    a0-a4/d0-d7,-(sp)    ;Store all registers
  164.     ;-- evaluate "real" coordinates --------;
  165.         move.l    window(PC),a4        ;^Window
  166.         moveq    #0,d3            ;for calculations
  167.         move.b    wd_BorderLeft(a4),d3    ;left border width
  168.         add    d3,d0            ;add to x
  169.         move.b    wd_BorderTop(a4),d3    ;window title height
  170.         add    #128,d3            ;+128 (bottom)
  171.         neg    d1            ;d3 - new level
  172.         add    d3,d1
  173.         neg    d2            ;d3 - old level
  174.         add    d3,d2
  175.     ;-- what colour to use? ----------------;
  176.         moveq    #3,d3            ;use blue
  177.         cmp    d2,d1            ;compare old vs. new
  178.         beq.b    .done            ;old = new -> leave
  179.         blo.b    .colour_ok        ;old > new -> blue is ok
  180.         exg    d2,d1            ;old < new -> change them
  181.         moveq    #0,d3            ;             and use grey
  182. .colour_ok    movem.l    d0-d2,-(sp)        ;rescue coordinates
  183.         move    d3,d0            ;set A Pen
  184.         move.l    wd_RPort(a4),a1        ;^Rast Port
  185.         gfx    SetAPen
  186.         movem.l    (sp)+,d0-d2
  187.     ;-- fill this box ----------------------;
  188.         move    d2,d3            ;ymax -> D3
  189.         move    d0,d2            ;xmax := xmin
  190.         add    #WINDOW_WIDTH/2-1,d2    ;       +bar width
  191.         move.l    wd_RPort(a4),a1        ;^RastPort
  192.         gfx    RectFill
  193.     ;-- done -------------------------------;
  194. .done        movem.l    (sp)+,a0-a4/d0-d7    ;Recall all registers
  195.         rts
  196.  
  197. *---------------------------------------------------------------*
  198. *    == LEVEL PROCESS ==                    *
  199. *                                *
  200. LevelProc
  201.     ;-- Get exiting signal -----------------;
  202.         sub.l    a1,a1            ;Get task structure
  203.         exec    FindTask
  204.         move.l    d0,leveltask
  205.         moveq    #-1,d0            ;get sig bit
  206.         exec    AllocSignal
  207.         move.b    d0,levelsigbit
  208.         cmp.b    #-1,d0            ;got no bit
  209.         beq    .error1
  210.         move.l    disptask(PC),a1        ;task is done
  211.         moveq    #0,d0
  212.         move.b    donesigbit(PC),d1
  213.         bset    d1,d0
  214.         exec    Signal            ; signals the exit
  215.     ;-- Allocate Maestro -------------------;
  216.         sub.l    a0,a0            ;no tags
  217.         maest    AllocMaestro
  218.         move.l    d0,maestro        ;^Maestro base
  219.         beq    .error2
  220.     ;-- Set Modus --------------------------;
  221.         move.l    maestro(PC),a0        ;^Maestro base
  222.         lea    modustags(PC),a1    ;^Modus tags
  223.         maest    SetMaestro        ;set it now
  224.     ;-- Read Status ------------------------;
  225.         move.l    maestro(PC),a0        ;^Maestro base
  226.         move.l    #MSTAT_Signal,d0    ;is input signal ok?
  227.         maest    GetStatus        ;get the card status
  228.         tst.l    d0
  229.         beq    .error3
  230.     ;-- Create Receive-Messageport ---------;
  231.         exec    CreateMsgPort        ;create a messageport
  232.         move.l    d0,rport        ; as receive port
  233.         beq    .error4
  234.     ;-- Init messages ----------------------;
  235.         move.l    rport(PC),d1        ;^Receive Reply Port
  236.         lea    msg1(PC),a0        ;^1st Message
  237.         lea    msg2(PC),a1
  238.         lea    msg3(PC),a2
  239.         move.l    buffer(PC),d0        ;get buffer ptr
  240.         move.l    d0,(dmn_BufPtr,a0)    ; set buffer1
  241.         add.l    #BUFSIZE,d0
  242.         move.l    d0,(dmn_BufPtr,a1)    ; set buffer2
  243.         add.l    #BUFSIZE,d0
  244.         move.l    d0,(dmn_BufPtr,a2)    ; set buffer 3
  245.         move.l    #BUFSIZE,(dmn_BufLen,a0) ;Set buffer length
  246.         move.l    #BUFSIZE,(dmn_BufLen,a1)
  247.         move.l    #BUFSIZE,(dmn_BufLen,a2)
  248.         move.l    d1,(MN_REPLYPORT,a0)    ;Set Reply-Port
  249.         move.l    d1,(MN_REPLYPORT,a1)
  250.         move.l    d1,(MN_REPLYPORT,a2)
  251.         move    #dmn_SIZEOF,(MN_LENGTH,a0) ;Set msg length
  252.         move    #dmn_SIZEOF,(MN_LENGTH,a1)
  253.         move    #dmn_SIZEOF,(MN_LENGTH,a2)
  254.     ;-- Start receive process --------------;
  255.         move.l    maestro(PC),a0        ;transmit msg to library
  256.         lea    msg1(PC),a1
  257.         maest    ReceiveData        ; the 1st (starts receiver!)
  258.         move.l    maestro(PC),a0
  259.         lea    msg2(PC),a1
  260.         maest    ReceiveData        ; and the 2nd
  261.         move.l    maestro(PC),a0
  262.         lea    msg3(PC),a1
  263.         maest    ReceiveData        ; and the 2nd
  264.     ;-- wait for messages ------------------;
  265. .mainloop    move.l    rport(PC),a0        ;maestix message?
  266.         exec    GetMsg            ; try to get it...
  267.         tst.l    d0            ; got one?
  268.         bne.b    .gotmaestro        ; then evaluate it
  269.         moveq    #0,d0            ;create wait mask
  270.         move.b    levelsigbit(PC),d1    ; signal for exiting
  271.         bset    d1,d0
  272.         move.l    rport(PC),a0        ; second, from receive port
  273.         move.b    MP_SIGBIT(a0),d1    ; sig bit
  274.         bset    d1,d0            ; set this bit
  275.         exec    Wait            ;wait for these events
  276.         move.b    levelsigbit(PC),d1    ; exit forced?
  277.         btst    d1,d0            ; test this bit
  278.         beq.b    .mainloop        ;not wanted -> main loop
  279.         bra.b    .exit            ; wanted -> leave
  280.     ;---- got a maestix event --------------;
  281. .gotmaestro    bsr    maestix            ;evaluate it
  282.         move.l    disptask(PC),a1        ;show new level
  283.         moveq    #0,d0
  284.         move.b    dispsigbit(PC),d1
  285.         bset    d1,d0
  286.         exec    Signal            ; signals the exit
  287.         bra.b    .mainloop        ;and try again
  288.     ;-- Leave task -------------------------;
  289. .exit        move.l    maestro(PC),a0        ;Return all messages
  290.         maest    FlushReceive
  291.         move.l    rport(PC),a0        ;delete receive port
  292.         exec    DeleteMsgPort
  293. .error4        move.b    levelsigbit(PC),d0    ;free signal bit
  294.         exec    FreeSignal
  295. .error3        move.l    maestro(PC),a0        ;Set maestro free
  296.         maest    FreeMaestro
  297. .error2        move.l    disptask(PC),a1        ;task is done
  298.         moveq    #0,d0
  299.         move.b    donesigbit(PC),d1
  300.         bset    d1,d0
  301.         exec    Signal            ; signals the exit
  302. .error1        rts                ;done (freed by DOS)
  303.  
  304. *-------------------------------------------------------*
  305. *  maestix    evaluate maestix event and draw level    *
  306. *    -» D0.l    ^Maestro Msg                *
  307. *                            *
  308. maestix        move.l    d0,a1            ;get ptr
  309.     ;-- Get pointers -----------------------;
  310.         move.l    dmn_BufPtr(a1),a0    ;a0: ^received data
  311.         move.l    dmn_BufLen(a1),d0
  312.         subq.l    #1,d0
  313.     ;-- Get left/right peak level ----------;
  314.         moveq    #0,d6            ;Left maximum to here
  315.         moveq    #0,d7            ;Right maximum here
  316. .getmax        move    (a0)+,d1        ;get one word (left)
  317.         bpl.b    .notneg_l
  318.         neg    d1            ;absolute value
  319. .notneg_l    cmp    d6,d1            ;new maximum?
  320.         blo.b    .nxtword_l
  321.         move    d1,d6            ;store as new maximum
  322. .nxtword_l    move    (a0)+,d1        ;get one word (right)
  323.         bpl.b    .notneg_r
  324.         neg    d1            ;absolute value
  325. .notneg_r    cmp    d7,d1            ;new maximum?
  326.         blo.b    .nxtword_r
  327.         move    d1,d7            ;store as new maximum
  328. .nxtword_r    subq.l    #4,d0            ;4 bytes less...
  329.         bcc.b    .getmax
  330.         move    d6,leftlevel        ;store new levels
  331.         move    d7,rightlevel
  332.     ;-- Re-send buffer to maestix ----------;
  333.         move.l    maestro(PC),a0        ;Re-send message
  334.         maest    ReceiveData        ; to maestix library
  335.     ;-- Done -------------------------------;
  336.         rts
  337.  
  338. *---------------------------------------------------------------*
  339. *    == DATA SECTION ==                    *
  340. *                                *
  341. disptask    dc.l    0            ;^Display task
  342. leveltask    dc.l    0            ;^Level task
  343. dispsigbit    dc.b    0            ;Display task signal bit
  344. levelsigbit    dc.b    0            ;Level task signal bit
  345. donesigbit    dc.b    0            ;Display task done sigbit
  346.         even
  347. maestbase    dc.l    0            ;^Maestix Lib Base
  348. intuibase    dc.l    0            ;^Intuition Lib Base
  349. gfxbase        dc.l    0            ;^Graphics Lib Base
  350. dosbase        dc.l    0            ;^DOS Lib Base
  351. stdout        dc.l    0            ;^Output FH
  352. maestro        dc.l    0            ;^Maestro Base
  353. rport        dc.l    0            ;^Receive MsgPort
  354. buffer        dc.l    0            ;^Data buffer
  355. window        dc.l    0            ;^Window structure
  356. msg1        ds.b    dmn_SIZEOF        ;^first message
  357. msg2        ds.b    dmn_SIZEOF        ;^second message
  358. msg3        ds.b    dmn_SIZEOF        ;^third message
  359. leftlevel    dc.w    0            ;left real level
  360. rightlevel    dc.w    0            ;right real level
  361. oldleft        dc.w    0            ;old left level
  362. oldright    dc.w    0            ;old right level
  363.  
  364. modustags    dc.l    MTAG_Input,INPUT_STD    ;use standard input
  365.         dc.l    MTAG_Output,OUTPUT_BYPASS
  366.         dc.l    TAG_DONE
  367.  
  368. tasktags    dc.l    NP_Entry,LevelProc    ;<- New process' tags
  369.         dc.l    NP_Priority,25
  370.         dc.l    NP_Name,.name
  371.         dc.l    TAG_DONE
  372. .name        dc.b    "Maestix level process",0
  373.         even
  374.  
  375. windowtags    dc.l    WA_IDCMP,IDCMP_CLOSEWINDOW ;<- New window's tags
  376.         dc.l    WA_Title,.title
  377.         dc.l    WA_InnerWidth,WINDOW_WIDTH
  378.         dc.l    WA_InnerHeight,129
  379.         dc.l    WA_DragBar,-1
  380.         dc.l    WA_DepthGadget,-1
  381.         dc.l    WA_CloseGadget,-1
  382.         dc.l    WA_Activate,-1
  383.         dc.l    WA_RMBTrap,-1
  384.         dc.l    TAG_DONE
  385. .title        dc.b    "DAT Level",0
  386.         even
  387.  
  388. maestname    dc.b    "maestix.library",0    ;Maestix name
  389. intuiname    dc.b    "intuition.library",0    ;Intuition name
  390. gfxname        dc.b    "graphics.library",0    ;Graphics name
  391. dosname        dc.b    "dos.library",0        ;DOS name
  392.         even
  393.  
  394. *---------------------------------------------------------------*
  395. *    == END ==                        *
  396. *                                *
  397.         END
  398.